import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path:"/",
    name:"login",
    component:()=>import("../views/login/index.vue"),
  },
  {
    path:"/reg",
    name:"reg",
    component:()=>import("../views/reg/index.vue"),
  },
  {
    path:"/fu",
    name:"fu",
    component:()=>import("../views/fu/index.vue"),
  },
  {
    path:"/detail/:id",
    name:"detail",
    component:()=>import("../views/detail/index.vue"),
  },
  { 
    path:"/layout",
    name:"layout",
    component:()=>import("../views/layout/index.vue"),
    children:[
      {
        path:"/layout/",
        name:"deme",
        component:()=>import("../views/layout/deme/index.vue"),
      },
      {
        path:"/layout/charts",
        name:"charts",
        component:()=>import("../views/layout/charts/index.vue"),
      },
      {
        path:"/layout/excel",
        name:"excel",
        component:()=>import("../views/layout/excel/index.vue"),
      },
      {
        path:"/layout/icons",
        name:"icons",
        component:()=>import("../views/layout/icons/index.vue"),
      },
      {
        path:"/layout/guide",
        name:"guide",
        component:()=>import("../views/layout/guide/index.vue"),
      },
      {
        path:"/layout/pdf",
        name:"pdf",
        component:()=>import("../views/layout/pdf/index.vue"),
      },
      {
        path:"/layout/tab",
        name:"tab",
        component:()=>import("../views/layout/tab/index.vue"),
      },
      {
        path:"/layout/zip",
        name:"zip",
        component:()=>import("../views/layout/zip/index.vue"),
      },
      {
        path:"/layout/home",
        name:'home',
        component:()=>import("../views/layout/home/index.vue")
      },
      {
        path:"/layout/list",
        name:'list',
        component:()=>import("../views/layout/list/index.vue")
      },
      {
        path:"/layout/car",
        name:'car',
        component:()=>import("../views/layout/car/index.vue")
      },
      {
        path:"/layout/my",
        name:'my',
        component:()=>import("../views/layout/my/index.vue")
      },
      {
        path:"/layout/ji",
        name:'ji',
        component:()=>import("../views/layout/ji/index.vue")
      },
      {
        path:"/layout/jing",
        name:'jing',
        component:()=>import("../views/layout/jing/index.vue")
      },
    ]
  },
]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
//路由拦截
router.beforeEach((to,from,next)=>{
  const token=localStorage.getItem("token")
  if(!token&&to.path!=='/'&&to.path!=='/reg'){
    next('/'),next("/reg")
  }else{
    next()
  }
})

export default router
